package org.yinxianren.www.study_02.study.httpTest;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Base64;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class PayTest02 {

    static  ThreadPoolExecutor  executor=new ThreadPoolExecutor(50,100,
            10, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());



    public static void main(String[] args) {
        //--------------------------------------
        executor.execute(()->{
            for(int i=0;i<10;i++){
                int j=i;
                executor.execute(()->{
                    payApply_1(j);
                    confirmPay_1(j);
                });
            }
        });

        //--------------------------------------

        executor.execute(()->{
            for(int i=0;i<10;i++){
                int j=i;
                executor.execute(()->{
                    payApply_2(j);
                    confirmPay_2(j);
                });
            }
        });


//--------------------------------------
        executor.execute(()->{
            for(int i=0;i<10;i++){
                int j=i;
                executor.execute(()->{
                    payApply_3(j);
                    confirmPay_3(j);
                });
            }
        });


    }



    public static void payApply_1(int i){
        try {
            Map<String, Object> map = new TreeMap<>();
            map.put("bizType","5");
            map.put("charset","utf-8");
            map.put("signType","MD5");
            map.put("merId","M201001");
            map.put("merOrderId","20190719000"+i);
            map.put("currency","CNY");
            map.put("amount","100");
            map.put("identityType","1");
            map.put("bankCardType","1");
            map.put("identityNum","350425199006012636");
            map.put("bankCardNum","6217001930018496795");
            map.put("bankCode","CCB");
            map.put("validDate","202211");
            map.put("securityCode","123");
            map.put("bankCardPhone","17605083552");
            map.put("payFee","10");
            map.put("terminalMerId","M201001-001");
            map.put("terminalMerName","test");
            map.put("returnUrl","http://...");
            map.put("noticeUrl","http://...");
            map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map,"1iiG15c2"));
            String tradeInfo = JsonUtils.objectToJson(map);
//            System.out.println(tradeInfo);
            tradeInfo= URLEncoder.encode(tradeInfo,"UTF-8");
            String postJson= new String( Base64.getEncoder().encode(tradeInfo.getBytes()),"UTF-8");
            String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://localhost:8030/kuaijie/pay/payApply", postJson);
            System.out.println(content);

//            System.out.println(postJson);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }}



    public static void confirmPay_1(int i){
        try {
            Map<String, Object> map = new TreeMap<>();
            map.put("bizType","5");
            map.put("charset","utf-8");
            map.put("signType","MD5");
            map.put("merId","M201001");
            map.put("merOrderId","20190719000"+i);
            map.put("smsCode","568373");
            map.put("terminalMerId","M201001-001");
            map.put("terminalMerName","test");
            map.put("payFee","10");
            map.put("noticeUrl","http://...");
            map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map,"1iiG15c2"));
            String tradeInfo = JsonUtils.objectToJson(map);

//            System.out.println(tradeInfo);
            tradeInfo= URLEncoder.encode(tradeInfo,"UTF-8");
            String postJson= new String( Base64.getEncoder().encode(tradeInfo.getBytes()),"UTF-8");
            String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://localhost:8030/kuaijie/pay/confirmPay", postJson);
            System.out.println(content);

//            System.out.println(postJson);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }}

    public static void payApply_2(int i){
        try {
            Map<String, Object> map = new TreeMap<>();
            map.put("bizType","5");
            map.put("charset","utf-8");
            map.put("signType","MD5");
            map.put("merId","M201002");
            map.put("merOrderId","20190719000"+i);
            map.put("currency","CNY");
            map.put("amount","80");
            map.put("identityType","1");
            map.put("bankCardType","1");
            map.put("identityNum","350425199006012636");
            map.put("bankCardNum","6217001930018496795");
            map.put("bankCode","CCB");
            map.put("validDate","202211");
            map.put("securityCode","123");
            map.put("bankCardPhone","17605083552");
            map.put("payFee","10");
            map.put("terminalMerId","M201002-001");
            map.put("terminalMerName","test");
            map.put("returnUrl","http://...");
            map.put("noticeUrl","http://...");
            map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map,"lXN7z498"));
            String tradeInfo = JsonUtils.objectToJson(map);
//            System.out.println(tradeInfo);
            tradeInfo= URLEncoder.encode(tradeInfo,"UTF-8");
            String postJson= new String( Base64.getEncoder().encode(tradeInfo.getBytes()),"UTF-8");
            String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://localhost:8030/kuaijie/pay/payApply", postJson);
            System.out.println(content);

//            System.out.println(postJson);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }}



    public static void confirmPay_2(int i){
        try {
            Map<String, Object> map = new TreeMap<>();
            map.put("bizType","5");
            map.put("charset","utf-8");
            map.put("signType","MD5");
            map.put("merId","M201002");
            map.put("merOrderId","20190719000"+i);
            map.put("smsCode","568373");
            map.put("terminalMerId","M201002-001");
            map.put("terminalMerName","test");
            map.put("payFee","10");
            map.put("noticeUrl","http://...");
            map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map,"lXN7z498"));
            String tradeInfo = JsonUtils.objectToJson(map);

//            System.out.println(tradeInfo);
            tradeInfo= URLEncoder.encode(tradeInfo,"UTF-8");
            String postJson= new String( Base64.getEncoder().encode(tradeInfo.getBytes()),"UTF-8");
            String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://localhost:8030/kuaijie/pay/confirmPay", postJson);
            System.out.println(content);

//            System.out.println(postJson);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }}


    public static void payApply_3(int i){
        try {
            Map<String, Object> map = new TreeMap<>();
            map.put("bizType","5");
            map.put("charset","utf-8");
            map.put("signType","MD5");
            map.put("merId","M201003");
            map.put("merOrderId","20190719000"+i);
            map.put("currency","CNY");
            map.put("amount","50");
            map.put("identityType","1");
            map.put("bankCardType","1");
            map.put("identityNum","350425199006012636");
            map.put("bankCardNum","6217001930018496795");
            map.put("bankCode","CCB");
            map.put("validDate","202211");
            map.put("securityCode","123");
            map.put("bankCardPhone","17605083552");
            map.put("payFee","10");
            map.put("terminalMerId","M201003-001");
            map.put("terminalMerName","test");
            map.put("returnUrl","http://...");
            map.put("noticeUrl","http://...");
            map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map,"357g4Y4v"));
            String tradeInfo = JsonUtils.objectToJson(map);
//            System.out.println(tradeInfo);
            tradeInfo= URLEncoder.encode(tradeInfo,"UTF-8");
            String postJson= new String( Base64.getEncoder().encode(tradeInfo.getBytes()),"UTF-8");
            String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://localhost:8030/kuaijie/pay/payApply", postJson);
            System.out.println(content);

//            System.out.println(postJson);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }}



    public static void confirmPay_3(int i){
        try {
            Map<String, Object> map = new TreeMap<>();
            map.put("bizType","5");
            map.put("charset","utf-8");
            map.put("signType","MD5");
            map.put("merId","M201003");
            map.put("merOrderId","20190719000"+i);
            map.put("smsCode","568373");
            map.put("terminalMerId","M201003-001");
            map.put("terminalMerName","test");
            map.put("payFee","10");
            map.put("noticeUrl","http://...");
            map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map,"357g4Y4v"));
            String tradeInfo = JsonUtils.objectToJson(map);

//            System.out.println(tradeInfo);
            tradeInfo= URLEncoder.encode(tradeInfo,"UTF-8");
            String postJson= new String( Base64.getEncoder().encode(tradeInfo.getBytes()),"UTF-8");
            String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://localhost:8030/kuaijie/pay/confirmPay", postJson);
            System.out.println(content);

//            System.out.println(postJson);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }}

}
